import React from 'react';
import axios from '../http/axios'
import url from '../config/url'
import { message } from 'antd';
const Checklogin = Cmp => {
    return class Hoc extends React.Component {
        state = { isLogin: false }
        render() {
            return (
                <>
                    {this.state.isLogin ? <Cmp {...this.props} /> : <div />}
                </>
            );
        }
        componentDidMount() {
            //请求服务端jwt预检
            axios.get(url.PreCheck).then(res => {
                if (res.data.errNo !== 0) {
                    message.error('请先登录')
                    this.props.history.push('/login')
                } else {
                    this.setState({
                        isLogin: true
                    })
                }
            })
        }
    }

}

export default Checklogin;
